import java.util.*;

class Student {
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        // System.out.printf("hashCode = %d\n", this.hashCode());
    }

    public int hashCode() {
        return this.name.hashCode();
    }

    public boolean equals(Object obj) {
        Student s = (Student)obj;
        // System.out.printf("Student equals\n");
        // return (age == s.age);
        return name.equals(s.name);
    }

    public String toString() {
        return name + "@" + age;
    }

    public void show() {
        System.out.println(this.toString());
    }
}

public class HashMapTest {
    static public void main(String [] args) {
        HashMap<String, Student> o = new HashMap<String, Student>();
        System.out.printf("hashMap size = %d\n", o.size());

        o.put("a", new Student("张三", 35));
        o.put("b", new Student("张有", 36));
        o.put("a", new Student("张人", 37));
        o.put("c", new Student("张三", 38));
        System.out.printf("hashMap size = %d\n", o.size());

        if (o.containsValue(new Student("张", 38))) {
            System.out.printf("value值是存在!\n");
        }

        if (o.containsKey("d")) {
            Student s = o.get("a");
            s.show();
        }

        Collection<Student> c = o.values();
        Set<String> st = o.keySet();

        // Iterator<Student> it = c.iterator();
        Iterator<String> it = st.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }
}
